package com.zm.xdata.service.publics.poster.util;

import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * 图片工具类
 */
public class ImgUtils {

    /**
     * 校验图片的宽高
     * @param file
     * @param width
     * @param height
     * @return
     */
    public static boolean verifySize(MultipartFile file,int width,int height) throws IOException
    {
        //获取图片的宽高
        BufferedImage image = ImageIO.read(file.getInputStream());
        if(null==image)
            throw new NullPointerException("上传的文件不是图片");

         if(width!=image.getWidth() || height!=image.getHeight())
             return false;
         return true;
    }
}
